package com.mic.yzzn.plc.web.controller.unitTest;

import com.mic.yzzn.plc.common.control.datastructure.PLCMission;
import com.mic.yzzn.plc.model.*;
import com.mic.yzzn.plc.web.controller.PLCController;

import java.rmi.RMISecurityManager;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by ASH on 16/5/3.
 */
public class RealTimeWriteTest {
    public static void main(String[] args) {
        System.setSecurityManager(new RMISecurityManager() {
            public void checkConnect (String host, int port) {}
            public void checkConnect (String host, int port, Object context) {}
        });

        Station station = new Station();
        station.setCode("tty.usbserial-A403QGGT-01");
        PLCController controller = new PLCController();


        PLCWriteRequest writeRequest = new PLCWriteRequest();
        writeRequest.setStation(station);
        writeRequest.setRequestType(PLCMission.PLCMissionTypeWriteFireAndAck);

        ArrayList<ContactPointData> contactPoints = new ArrayList<>();
        ContactPointData p2 = new ContactPointData(new ContactPoint("D1100"), "1234");
        ContactPointData p3 = new ContactPointData(new ContactPoint("R1002"), "0");
        ContactPointData p4 = new ContactPointData(new ContactPoint("R1003"), "1");
        ContactPointData p5 = new ContactPointData(new ContactPoint("R1004"), "0");
        ContactPointData p6 = new ContactPointData(new ContactPoint("R1005"), "1");
        ContactPointData p7 = new ContactPointData(new ContactPoint("R1006"), "0");
        ContactPointData p8 = new ContactPointData(new ContactPoint("R1007"), "1");
        ContactPointData p9 = new ContactPointData(new ContactPoint("R1008"), "0");
        ContactPointData p10 = new ContactPointData(new ContactPoint("D20011"), "1234");
        ContactPointData p11 = new ContactPointData(new ContactPoint("R100H"), "0"); // 非法点位

        contactPoints.add(p2);
        contactPoints.add(p3);
        contactPoints.add(p4);
        contactPoints.add(p5);
//        contactPoints.add(p6);
//        contactPoints.add(p7);
//        contactPoints.add(p8);
//        contactPoints.add(p9);
//        contactPoints.add(p10);
//        contactPoints.add(p11);

        writeRequest.setDataList(contactPoints);

        System.out.println(controller.realtimeWrite(writeRequest));
    }
}
